package com.emokili.ewa.app.controller;

import com.emokili.ewa.common.utils.R;
import com.emokili.ewa.core.frame.entity.MemberEntity;
import com.emokili.ewa.core.frame.service.FrameService;
import com.emokili.ewa.core.frame.service.MemberFrameService;
import com.emokili.ewa.core.frame.vo.FrameVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/v1/app")
public class FrameController {

    @Autowired
    MemberFrameService memberFrameService;
    @Autowired
    private FrameService frameService;

    /**
     * 绑定相框
     *
     * @param request
     * @param serialNumber
     * @return
     */
    @RequestMapping("/bind/{serialNumber}")
    @ResponseBody
    public R bind(HttpServletRequest request, @PathVariable String serialNumber) {
        MemberEntity entity = (MemberEntity) request.getAttribute("member");
        memberFrameService.bind(entity.getId(), serialNumber);
        return R.ok();
    }

    @GetMapping("/getBindStatus")
    @ResponseBody
    public R getBindStatus(@RequestParam String serialNumber) {
        log.info("get bind status start");
        memberFrameService.getBindStatus(serialNumber);
        return R.ok();
    }

    /**
     * 相框设置
     *
     * @param frameVo
     * @return
     */
    @PostMapping("/settings")
    @ResponseBody
    public R settings(@RequestBody FrameVo frameVo) {
        frameService.update(frameVo);
        return R.ok();
    }

}
